package com.itheima.sky.dao;

import com.itheima.sky.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description CategoryMapper
 * @Author jiangning
 * @Date 2024-06-28
 */
@Mapper
public interface CategoryMapper {
    @Select("select * from category;")
    List<Category> getAllCates();


    @Insert("insert into category values(null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Category category);


//    //查询所有的类别
//    @Select("select * from category order by sort")
//    List<Category> findAll();


    //根据id删除分类
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);


    @Update("update category set type=#{type},name=#{name},sort=#{sort},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    void updateById(Category category);


    //查询所有类别，按照sort字段排序
    @Select("select * from category order by sort asc")
    List<Category> findAll();


    //pan
    //根据id删除分类
    @Delete("delete from category where id = #{id}")
    void deleteByIdP(Long id);

    @Insert("insert into category values(null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void saveP(Category category);


    @Select("select * from category where id = #{id}")
    Category findById(Long categoryId);

    //查询所有的类别
    @Select("select * from category order by sort")
    List<Category> findAllP();

    @Update("update category set type=#{type},name=#{name},sort=#{sort},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    void updateByIdP(Category category);


    List<Category> list(@Param("type") Integer type);

    //o
    @Select("select * from category")
    List<Category> findCategoryList();

    /**
     * 根据Type查询类别集合
     * @param type
     * @return
     */

    List<Category> findList(Integer type);

}
